package com.google.projectulator;

import java.util.HashMap;

import com.google.projectulator.exception.ProjectulatorConfigurationException;

/**
 * Map extension that provides support for configuration.
 * 
 * @author Lance Woodson
 *
 */
@SuppressWarnings("serial")
public class Config extends HashMap<String, String> {
	/**
	 * Retrieves the value associated with the paramName, or results in a ProjectulatorConfigurationException
	 * being thrown if one doesn't exist.
	 * @param paramName
	 * @return
	 */
	public String getRequired(String paramName) {
		if (!containsKey(paramName)) {
			throw new ProjectulatorConfigurationException(paramName + " not defined in plugin configuration");
		}
		return get(paramName);
	}
	
	/**
	 * Retrieves the value associated with the paramName, or the defaultValue if none exists.
	 * @param paramName
	 * @param defaultValue
	 * @return
	 */
	public String getOrDefault(String paramName, String defaultValue) {
		String result = get(paramName);
		if (result == null) {
			result = defaultValue;
		}
		return result;
	}
}
